/**
 * Created with IntelliJ IDEA.
 * Description:异常处理
 * User: LianBao
 * Date: 2024-03-13
 * Time: 17:13
 */

public class Test {


    public static void main(String[] args) throws Exception {
        try {
            System.out.println(10 / 0);
        } catch (ArithmeticException e) {
            e.printStackTrace();
        }
    }

    public static int countSegments(String s) {
        if (s == null || s.length() == 0) {
            return 0;
        }
        s = s.trim();
        String[] ret = s.split(" ");
        int count = 0;
        for (int i = 0; i < ret.length; i++) {
            if (ret[i] != "") {
                count++;
            }
        }
        return count;
    }

    public static int countSegments2(String s) {
        int count = 0;
        String[] strings = s.split(" ");
        for (String st : strings) {
            if (st.trim().length() != 0) {
                count++;
            }
        }
        return count;
    }

    public static void main2(String[] args) {
        String str = "aa  ab   ..,";
        System.out.println(countSegments(str));
        System.out.println(countSegments2(str));
    }

    public static void main1(String[] args) {
        int[] array = null;
        try {
            System.out.println(array.length);
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    }
}

